﻿<table id="table" class="layui-table" lay-filter="table"></table>
<script type="text/html" id="rowbar">
    @Html.LayuiButton("position", "三维定位", "layui-btn layui-btn-xs", "/Monitor/MonitorData/Index")
    {{#  if(!d.Normal && d.IsDeal == 0){ }}
    @Html.LayuiButton("confirm", "确认", "layui-btn layui-btn-danger layui-btn-xs", "/Monitor/MonitorData/Index")
    {{#  } }}
</script>
<script>
    layui.use(['table', 'layer'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        layui.tableReload = function () {
            table.reload("table", {
                where: {},//getWhere(),
                page: { curr: 1 }
            });
        }
        // 渲染表格
        table.render({
            id: "table",
            elem: '#table',
            method: "post",
            url: 'List',
            cellMinWidth: 80,
            cols: [
                [
                    //{ type: 'checkbox' },
                    { field: 'EquipmentCode', title: '设备编号' },
                    { field: 'ParkCode', title: '所属园区' },
                    { field: 'StorehouseCode', title: '所属仓库' },
                    { field: 'MonitorType', title: '监控类型' },
                    { field: 'MonitorValue', title: '监控数值' },
                    { field: 'AlarmStatus', title: '报警状态' },
                    {
                        field: 'IsDeal', title: '处理状态', templet: function (d) {
                            return d.IsDeal == 0 ? "未处理" : "已处理";
                        }
                    },
                    { field: 'CreateDate', title: '创建日期' },
                    { fixed: 'right', title: '操作', align: 'center', toolbar: '#rowbar', width: '150' }
                ]
            ],
            done: function (res, curr, count) { //res 即为原始返回的数据
                var that = this.elem.next();
                var currPage = '/Monitor/MonitorData/Index';
                $.each(res.data, function (index, item) {
                    //if (!item.Normal) {
                    //    that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", "red");
                    //    if (parent.layui.getCurrTab() != currPage) {
                    //        if (item.IsDeal == 0) {
                    //            parent.layer.alert("温度异常，请查看！", function (index) {
                    //                parent.layuimini.changeTab(currPage);
                    //                parent.layer.close(index);
                    //            });
                    //            return;
                    //        }
                    //    }
                    //}
                })
                setTimeout(layui.tableReload, 10000);
            },
            loading: false,
            event: true,
            page: { limit: 20 }
        });
        //监听工具条
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'confirm') {
                $.ajax({
                    url: 'Confirm',
                    data: { id: data.ID },
                    success: function (res) {
                        layer.alert(res.msg, function (index) {
                            layer.close(index);
                            if (res.count > 0) {
                                layui.tableReload();
                            }
                        })
                    }
                });
            }
            else if (layEvent === 'position') {
                layer.open({
                    type: 2,
                    title: '定位库位',
                    maxmin: false,
                    area: ['100%', '100%'],
                    content: '/Resource/Show3D/Show3D'
                });
            }
        });
    });
</script>
